#include <string.h>

#include <kernel.h>

static struct list obj_list[CLASS_TYPE_NUKNOWN] = {
	LIST_INIT(obj_list[CLASS_TYPE_DEVICE]),
	LIST_INIT(obj_list[CLASS_TYPE_THREAD]),
};

/* 初始化一个object对象，只有经过初始化的object对象才能正常使用 */
err_t object_init(struct object *obj, const char *name)
{
	assert(obj != NULL);

	strncpy(obj->name, name, NAME_MAX_SIZE - 1);

	list_add_tail(&obj->list, &obj_list[obj->type]);

	return 0;
}

/* 根据名字找到一个object对象 */
struct object *object_find(const char *name, const enum class_type type)
{
	struct object *obj;

	list_for_each_entry(obj, &obj_list[type], list) {
		if (strncmp(obj->name, name, NAME_MAX_SIZE) == 0)
			return obj;
	}

	return NULL;
}

/* 反初始化一个object对象 */
void object_deinit(struct object *obj)
{
	list_del(&obj->list);
}

